﻿
@{
    ViewData["Title"] = "UpdateView";
    Layout = null;
}

<link href="~/libs/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />

    <form class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">工作站编号</label>
                <div class="layui-input-block">
                <input type="text" id="workStationCode" name="workStationCode" autocomplete="off" class="layui-input" readonly>
                </div>
            </div>
            @* <button type="button" class="layui-btn layui-bg-purple" onclick="codeRandom()">紫色按钮</button> *@

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">工作站名称</label>
            <div class="layui-input-block">
                <input type="text" id="workStationName" name="workStationName" autocomplete="off" placeholder="工作站名称" lay-verify="required" class="layui-input" >
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">工作站地点</label>
            <div class="layui-input-block">
                <input type="text" id="workStationLocations" name="workStationLocations" autocomplete="off" placeholder="工作站地点" lay-verify="required" class="layui-input" >
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label">所在车间</label>
                <div class="layui-input-inline">
                    <select name="workshopId" id="workshopId" lay-filter="workshopId">
                        <option value="0">请选择</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label">所属工序</label>
                <div class="layui-input-inline">
                    <select name="processId" id="processId" lay-filter="processId">
                        <option value="0" accesskey="">请选择</option>
                        <option value="1" >材料切割</option>
                        <option value="2" >成型</option>
                        <option value="3" >连接</option>
                        <option value="4" >打磨</option>
                        <option value="5" >涂漆/上油</option>
                        <option value="6" >部件组装</option>
                    </select>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="remark" name="remark" class="layui-textarea" lay-filter="remark" ></textarea>
                </div>
            </div>
        </div>

        <div class="layui-form-item" pane>
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input type="radio" name="isNo" id="isNo" value="1" title="是" checked >
                <input type="radio" name="isNo" id="isNo" value="0" title="否" >
            </div>
        </div>

        @* 隐藏的图片上传 *@
        <div style="display:none;">
            <div class="layui-input-block">
                <input type="text" id="image" name="image" autocomplete="off" placeholder="工作站地点" lay-verify="required" class="layui-input" >
            </div>
        </div>


        <div class="layui-form-item">
            <button class="layui-btn" lay-submit lay-filter="demo2">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>

    </form>


<script src="~/libs/layui-v2.5.6/layui/layui.js"></script>
<script src="~/libs/jquery/jquery.js"></script>

    <script>

        $(function () {
            //获取车间信息
           getWorkshopList();
           //获取表单数据
           GetTheData()
        });


        //获取表单数据
        function GetTheData(){
              console.log("11111111111111111111111111111");
              console.log(@ViewBag.id);
            $.ajax({
                url:'/WorkStation/SpecificData',
                type:'get',
                 data: {
                     id: @ViewBag.id
                 } ,
                 success:function(data){
                    console.log(data);
                    $('#workStationCode').val(data.workStationCode);
                    $('#workStationName').val(data.workStationName);
                    $('#workStationLocations').val(data.workStationLocations);
                    $('#workshopId').val(data.workshopId);
                     layui.form.render("select");
                    $('#processId').val(data.processId);
                     layui.form.render("select");
                    $('#remark').val(data.remark);
                    $('#isNo').val(data.isNo);
                    $('#image').val(data.image);

                    layui.form.render("radio");
                }
            })
        }



        //获取车间信息
        function getWorkshopList() {
             $.ajax({
                url:'/WorkStation/WorkshopSetupsList',
                type:'get',
                async:false,
                success:function(res){
                    console.log(res);
                    var html = '<option value="0">"请选择"</option>';
                    $.each(res.data,function(i,item){
                        html += '<option value="'+item.id+'" readonly>'+item.workShopName+'</option>';
                    })
                    $('#workshopId').html(html);
                    layui.form.render('select');
                }
            })
        }


           layui.use(['form'], function(){
          var form = layui.form;
          var layer = layui.layer;



          // 提交事件
          form.on('submit(demo2)', function(data){
            var field = data.field; // 获取表单字段值
            
             console.log(field);
             field.id = @ViewBag.id;
            field.workshopId = parseInt(field.workshopId);
            field.processId = parseInt(field.processId);
            field.isNo = parseInt(field.isNo);
            $.ajax({
                url:'/WorkStation/UpdateQRCode',
                type:'post',
                data:field,
                success:function(res){
                    console.log(res);
                    if(res==1){
                    layer.msg(res.msg,{icon:1,time:1000,title:'OK了,老铁'},function(){

                        reset();
                    });
                    }else{
                        layer.msg(res.msg,{icon:2,time:1000},function(){
                            return "已经有相同的工作站名字了";
                        });
                    }
                }
            })

            return false; // 阻止默认 form 跳转
          });

        });


        /// 生成随机编号
        function codeRandom(){
            $.ajax({
                url:'/WorkStation/CodeRandom',
                type:'get',
                success:function(res){
                    console.log(res);
                    $('#workStationCode').val(res.data);
                }
            })
        }

        //返回原页面
        function reset(){
            console.log("返回");
        //在当前iframe => 关闭当前iframe
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
        }


    </script>


